<template>
	<view style="padding: 20rpx;">
		<view class="box" v-if="commentList.length">
			<view v-for="item in commentList" :key="item.id" style="border-bottom: 2rpx solid #eee; padding: 20rpx 0;">
				<view style="font-size: 34rpx; margin-bottom: 10rpx;" @click="goToDetail(item.comment.businessId)">
					{{ item.comment.businessName }} <uni-icons type="right" size="18" color="#888" style="position: relative; top: 2rpx;"></uni-icons>
				</view>
				
				<view style="display: flex; padding-top: 20rpx; ">
				<view style="display: flex; flex-direction: column; align-items: center;grid-gap: 10rpx;">
					<image :src="item.comment.userAvatar" style="width: 120rpx; border-radius: 50%;" mode="widthFix"></image>
					<view style="color: #888;">{{ item.comment.userName }}</view>
				</view>
					<view style="flex: 1; display: flex; flex-direction: column; justify-content: space-between;">
						
						<view>{{item.good.name}} </view>
						<view style="flex: 1; padding-top: 30rpx;padding-left: 20rpx; font-size: 24rpx;">评价内容：{{ item.comment.content }}</view>
						<view style="flex: 1"><uni-rate :value="item.comment.star" readonly></uni-rate></view>
					</view>
					<view style="font-size: 24rpx; color: #888; display: flex; align-items: flex-end;">{{ item.comment.time }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				commentList:[],
				user: uni.getStorageSync('xm-user'),
				ordersItemList:[]
			}
		},
		onLoad() {
			this.load()
			
		},
		methods: {
			goToDetail(businessId){
				uni.navigateTo({
					url: '/pages/detail/detail?businessId=' + businessId 
				})
			},
			async load(){
				await this.$request.get('/comment/selectAll',{ userId:this.user.id }).then(res => {
					this.commentList = res.data || []
				})
				for (const com of this.commentList) {
					console.log('1')
					await this.nameLoad(com.orderId)
				}
				const  ceshi = this.commentList.map((element, index) => {
				  return {  
				    comment: element,  
				    good: this.ordersItemList[index]  
				  };  
				});
				this.commentList=ceshi
				console.log(this.commentList)
				
			},
			async  nameLoad(orderId) {	
				await  this.$request.get('/orders/selectById/' + orderId).then(res => {
					const mes = res.data || []
					this.ordersItemList=this.ordersItemList.concat(mes)
				})
				// await this.$request.get('/ordersItem/selectAll', {
				// 		orderId: orderId
				// 	}).then(res => {
				// 		const mes = res.data || []
				// 		this.ordersItemList=this.ordersItemList.concat(mes)
				// 		console.log(this.ordersItemList)
				// 	})
					
					
				
				
				}
			
		}
	}
</script>

<style>

</style>
